#include<cstdio>
int a[1010],b[1010],c[1010];
int n,i,j,max;
int main()
{
    freopen("chorus.in","r",stdin);
     freopen("chorus.out","w",stdout);
    scanf("%d",&n);
    for(i=1;i<=n;i++)scanf("%d",&a[i]);
    for(i=1;i<=n;i++)
    {
        b[i]=1;
        for(j=1;j<i;++j)
            if(a[i]>a[j]&&b[j]+1>b[i])b[i]=b[j]+1;
    }
    for(i=n;i>=1;i--)
    {
        c[i]=1;
        for(j=i+1;j<=n;++j)
            if(a[j]<a[i]&&c[j]+1>c[i])c[i]=c[j]+1;
    }
    for(i=1;i<=n;i++)
        if(b[i]+c[i]>max)max=b[i]+c[i];
    printf("%d",n-max+1);
    fclose(stdin);
	 fclose(stdout);
}
